import type {
  ActionConfig,
  DataRecord,
  FormConfig,
  PageConfig,
  PaginationConfig,
  SearchFieldConfig,
  TableActionConfig,
  TableColumn,
} from './config.type'

/**
 * 完整的页面配置
 */
const config = {
  // 页面基本信息
  page: {
    title: '用户管理',
    description: '管理系统中的用户信息',
    permission: 'acl:user',
    targetNameField: 'username',
  } as PageConfig,

  // API接口配置
  api: {
    GET_URL: '/user/list',
    CREATE_URL: '/user/save',
    UPDATE_URL: '/user/update',
    DELETE_URL: '/user/remove',
    BATCH_DELETE_URL: '/user/batchRemove',
  },

  // 搜索配置
  search: {
    fields: [
      {
        prop: 'username',
        label: '用户名',
        type: 'input',
        placeholder: '按用户名搜索',
        clearable: true,
      },
      {
        prop: 'name',
        label: '姓名',
        type: 'input',
        placeholder: '按姓名搜索',
        clearable: true,
      },
    ] as SearchFieldConfig[],
    showReset: true,
    searchButtonText: '搜索',
    resetButtonText: '重置',
  },

  // 表格列配置
  tableColumns: [
    {
      type: 'selection',
      label: '选择',
      width: 'auto',
      align: 'center',
    },
    {
      type: 'index',
      label: 'ID',
      width: 'auto',
      align: 'center',
    },

    {
      prop: 'username',
      label: '用户名',
      minWidth: 'auto',
      align: 'center',
      sortable: true,
    },
    {
      prop: 'name',
      label: '姓名',
      minWidth: 'auto',
      align: 'center',
      showOverflowTooltip: true,
    },
    {
      prop: 'roleName',
      label: '角色',
      showOverflowTooltip: true,
      minWidth: 'auto',
      align: 'center',
    },

    {
      prop: 'createAt',
      label: '创建时间',
      type: 'date',
      width: 180,
      align: 'center',
      sortable: true,
      dateConfig: {
        format: 'YYYY-MM-DD',
      },
    },
    {
      prop: 'updateAt',
      label: '更新时间',
      type: 'date',
      width: 180,
      align: 'center',
      sortable: true,
      dateConfig: {
        format: 'YYYY-MM-DD',
      },
    },
    //  操作列在page.vue中统一配置
  ] as TableColumn<DataRecord>[],

  // 表格操作列配置
  tableActionColumn: {
    width: 'auto' as const,
    align: 'center' as const,
    fixed: 'right' as const,
  },

  // 表格操作列按钮配置
  tableActions: [
    {
      text: '编辑',
      label: '编辑',
      type: 'primary' as const,
      size: 'small' as const,
      plain: true,
      permission: 'btn.User.update',
      action: 'edit' as const,
    },
    {
      text: '删除',
      label: '删除',
      type: 'danger' as const,
      size: 'small' as const,
      plain: true,
      permission: 'btn.User.remove',
      action: 'delete' as const,
    },
  ] as TableActionConfig[],

  // 表单配置
  form: {
    fields: [
      {
        prop: 'username',
        label: '用户名',
        type: 'input',
        placeholder: '请输入用户名',
        required: true,
        maxlength: 50,
        showWordLimit: true,
      },
      {
        prop: 'name',
        label: '姓名',
        type: 'input',
        placeholder: '请输入姓名',
        maxlength: 50,
        showWordLimit: true,
      },
      {
        prop: 'password',
        label: '密码',
        type: 'input',
        inputType: 'password',
        showPassword: true,
        placeholder: '请输入密码',
        required: true,
      },
    ],
    rules: {
      username: [
        { required: true, message: '请输入用户名', trigger: 'blur' },
        { min: 3, max: 50, message: '用户名长度在 3 到 50 个字符', trigger: 'blur' },
      ],
      password: [
        { required: true, message: '请输入密码', trigger: 'blur' },
        { min: 6, message: '密码长度不能少于 6 个字符', trigger: 'blur' },
      ],
    },
    labelWidth: '100px',
    dialogWidth: '600px',
    addTitle: '新增用户',
    editTitle: '编辑用户',
  } as FormConfig,

  // 操作按钮配置
  actions: {
    add: {
      text: '新增用户',
      icon: 'Plus',
      permission: 'btn.User.add',
    },
    batchDelete: {
      text: '批量删除',
      icon: 'Delete',
      permission: 'btn.User.remove',
    },
  } as ActionConfig,

  // 分页配置
  pagination: {
    pageSizes: [10, 20, 50, 100],
    defaultPageSize: 10,
  } as PaginationConfig,

  // 消息配置
  messages: {
    loadSuccess: '用户获取成功',
    loadError: '用户获取失败',
    addSuccess: '用户添加成功！',
    addError: '用户添加失败',
    editSuccess: '用户修改成功！',
    editError: '用户修改失败',
    deleteSuccess: '删除成功',
    deleteError: '删除失败',
    batchDeleteSuccess: '批量删除成功',
    batchDeleteError: '批量删除失败',
    uploadSuccess: 'Logo上传成功',
    uploadError: 'Logo图片上传失败',
    selectDeleteItems: '请选择要删除的数据',
    deleteConfirm: '确定要删除这个用户吗？删除后无法恢复！',
    batchDeleteConfirm: '确定要删除选中的 {count} 个用户吗？删除后无法恢复！',
    assignRoleSuccess: '角色分配成功',
    assignRoleError: '角色分配失败',
    assignRoleConfirm: '确定要将选中的 {count} 个用户分配给角色 "{roleName}" 吗？',
  },
}

export default config
